package Order.DAO;

import Order.Entity.Customer;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class CustomerDAO implements IRepository<Customer> {

    public CustomerDAO(EntityManager em) {
        this.em = em;
    }

    public Customer merge(Customer entity) {
        return em.merge(entity);
    }

    public Customer persist(Customer entity) {
        em.persist(entity);
        return entity;
    }

    public void remove(Customer entity) {
        entity = em.merge(entity);
        em.remove(entity);
    }
    private EntityManager em;

    public Customer FindById(Integer id) {
        Query query = em.createQuery("select m from Customer m where m.id = " + id);
        return (Customer)query.getSingleResult();
    }
}
